/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-16 11:54:43
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-16 13:41:17
 */
import 'package:flutter_data_center/model/light/light_module.dart';
import 'package:flutter_data_center/net/dio_utils.dart';
import 'package:get/get.dart';

class LightController extends GetxController {
  int _total = 0;
  int get total => _total;
  int _open = 0;
  int get open => _open;

  void getLightStatistics() async {
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.lightStatistics,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      _total = data['total'];
      _open = data['open'];
      update();
    }
  }

  // 菜单列表
  List<LightModel> _lightList = [];
  List get lightList => _lightList;
  void getLights() async {
    _lightList = [];
    ResponseInfo responseInfo = await DioUtils.instance.getRequest(
      url: HttpHelper.lightList,
    );
    if (responseInfo.success) {
      var data = responseInfo.data;
      for (var item in data) {
        _lightList.add(LightModel.fromJson((item)));
      }
      update();
    }
  }
}
